# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=pycairo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-cairo")
pkgver=1.28.0
pkgrel=1
pkgdesc="Python bindings for the cairo graphics library (mingw-w64)"
url="https://pycairo.readthedocs.io"
msys2_repository_url="https://github.com/pygobject/pycairo"
msys2_references=(
  'purl: pkg:pypi/pycairo'
)
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:LGPL-2.1-only OR MPL-1.1')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-ninja")
provides=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=(https://github.com/pygobject/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz{,.sig})
sha256sums=('26ec5c6126781eb167089a123919f87baa2740da2cca9098be8b3a6b91cc5fbc'
            'SKIP')
validpgpkeys=('0EBF782C5D53F7E5FB02A66746BD761F7A49B0EC')

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      ../"${_realname}-${pkgver}"

  meson compile
}

check() {
  cd "build-${MSYSTEM}"

  meson test
}

package() {
  cd "build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install
  shopt -s globstar
  rm "${pkgdir}"${MINGW_PREFIX}/**/*.dll.a

  MSYS2_ARG_CONV_EXCL="-p" python -m compileall \
    -o 0 -o 1 -q -s"${pkgdir}" -p"/" "${pkgdir}${MINGW_PREFIX}/lib/python"*

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/"COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python-cairo"
}
